package com.sgb.kjwl.view.ui.activity.manage;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.Html;
import android.text.InputType;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;

import com.alibaba.sdk.android.vod.upload.model.UploadFileInfo;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityWebsiteUpdataQyjjBinding;
import com.sgb.kjwl.di.manage.DaggerEnterpriseManageComponent;
import com.sgb.kjwl.di.manage.EnterpriseManageModule;
import com.sgb.link.entity.PickFilterEntity;
import com.sgb.kjwl.view.ui.adapter.manage.AddViewAdapter;
import com.sgb.kjwl.view.widget.manage.WebsiteUtils;
import com.sgb.link.view.widget.OneAndTwoLevelMultipleChoiceWindow;
import com.swgk.core.customview.DecimalInputTextWatcher;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.manage.WebsiteInfoEntity;
import com.swgk.core.base.model.entity.VideoBean;
import com.sgb.kjwl.utils.ReplaceUtils;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.knowledgeshare.view.activity.PlayListActivity;
import com.sgb.link.view.widget.TwoLevelMultipleChoiceWindow;
import com.sgb.kjwl.view.widget.manage.MImgGetter;
import com.sgb.kjwl.viewmodel.manage.WebsiteUpDataQiYeXiXinModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import javax.inject.Inject;

/**
 * @author 张驰
 * @date 2021/5/12 15:03
 * @Description 企业网店发布模块中企业简介数据编辑
 * @name com.sgb.kjwl.view.ui.activity.manage
 */
public class WebsiteUpDataQiYeXiXinActivity extends WebSiteBuildBaseActivity {

    @Inject
    WebsiteUpDataQiYeXiXinModel viewModel;
    private ActivityWebsiteUpdataQyjjBinding binding;
    private RequestManager requestManager;

    public static final int RESULT_CODE_SELECT = 100; // 返回
    public static final int REQUEST_CODE_SELECT = 101;// 请求

    private String avatar = "";
    private List<PickFilterEntity> picCompanyNature;
    private List<PickSelectEntity> picCompanyUnit;
    private List<PickSelectEntity> picCompanyTurnover;
    private List<PickSelectEntity> picCompanyIsProcessing;
    private List<PickSelectEntity> pickQualityControl;
    private List<PickFilterEntity> pickManageAuth;
    private List<PickSelectEntity> pickBusinessType;
    private WebsiteInfoEntity.BusinessInfoEntity mBusinessInfoEntity;

    private List<PickFilterEntity<List<PickFilterEntity>>> pickAreas = new ArrayList<>();

    private List<PickFilterEntity<List<PickFilterEntity>>> pickTempAreas = new ArrayList<>();

    private int mBusinessType = 1;//业务类型---默认服务型
    private int mBusinessTypePosition = 0;

    private List<PickFilterEntity> historyList = new ArrayList<>();

    private boolean isServiceArea;

    private List<PickFilterEntity> reallyList = new ArrayList<>(); //这个公用区域
    private List<PickFilterEntity> reallyProductList = new ArrayList<>(); //这个生产区域

    // 1。新增模式下，暂存本地视频文件路径 2.编辑模式，回显视频播放路径，当执行删除操作时，用来判断用户是否删除已上传的视频，当用户重新提交上传时，执行1操作
    private String localVideoUrl = "";

    private List<WebsiteInfoEntity.ServiceAreaEntity> mServiceAreas = new ArrayList<>();

    private List<PickFilterEntity> mReallyServiceArea = new ArrayList<>();

    private List<PickFilterEntity> mHistoryServiceArea = new ArrayList<>();

    private List<WebsiteInfoEntity.ServiceAreaEntity> mPostServiceAreas = new ArrayList<>();//提交的

    private List<WebsiteInfoEntity.ServiceAreaEntity> mServiceAreas1 = new ArrayList<>();

    private List<PickFilterEntity> mReallyServiceArea1 = new ArrayList<>();

    private List<PickFilterEntity> mHistoryServiceArea1 = new ArrayList<>();


    private List<WebsiteInfoEntity.ServiceAreaEntity> mPostServiceAreas1 = new ArrayList<>();//提交的

    private List<PickFilterEntity> mPostAreas = new ArrayList<>();
    private List<PickFilterEntity> mProductPostAreas = new ArrayList<>();
    //经营类型
    private List<PickFilterEntity<List<PickFilterEntity>>> manageTypeList = new ArrayList<>();

    private AddViewAdapter mAddViewAdapter;
    private WebsiteInfoEntity.ServiceAreaEntity mPostServiceEntity;
    private String mSubEdit;
    private OneAndTwoLevelMultipleChoiceWindow window;
    private List<PickFilterEntity> comReallyTypes = new ArrayList<>();

    private int leibusinessType=-1;
    public static void start(Context context) {
        Intent intent = new Intent(context, WebsiteUpDataQiYeXiXinActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseManageComponent.builder().appComponent(appComponent).
                enterpriseManageModule(new EnterpriseManageModule(this)).
                build().inject(this);

    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_website_updata_qyjj);
        requestManager = Glide.with(this);
        binding.include.titleView.setText("信息简介");
        binding.tvUpdate.setOnClickListener(this);
        binding.include.ivBack.setOnClickListener(this);
        binding.linUploadAvatar.setOnClickListener(this);
        binding.linIndustry.setOnClickListener(this);
        binding.linCompanyNature.setOnClickListener(this);
        binding.linOperatingAddress.setOnClickListener(this);
        binding.manageType.setOnClickListener(this);
//        binding.linCompanyTurnover.setOnClickListener(this);
//        binding.linIsProcessing.setOnClickListener(this);
//        binding.linQualityControl.setOnClickListener(this);
//        binding.linManageAuth.setOnClickListener(this);
//        binding.linMarketArea.setOnClickListener(this);
        binding.linVideoUpload.setOnClickListener(this);
        //binding.linCompanyMode.setOnClickListener(this);
        binding.tvIntroduction.setOnClickListener(this);
        binding.linRecordUnitName.setOnClickListener(this);
        binding.linCompanyUnit.setOnClickListener(this);
        binding.ivDeleteVideo.setOnClickListener(this);
        binding.linServiceScope.setOnClickListener(this);
        binding.linBusinessType.setOnClickListener(this);
        binding.tvAdd.setOnClickListener(this);
        binding.tvAddProduct.setOnClickListener(this);
        binding.alltype.setOnClickListener(this);
        binding.tvConcat.setInputType(InputType.TYPE_CLASS_TEXT);
        binding.tvPhone.setInputType(InputType.TYPE_CLASS_PHONE);
        binding.tvFixedNumber.setInputType(InputType.TYPE_CLASS_PHONE);
        //binding.tvStaffNumber.setInputType(InputType.TYPE_CLASS_NUMBER);
        //binding.tvDeveloperNumber.setInputType(InputType.TYPE_CLASS_NUMBER);
       // binding.tvMonthProduction.setInputType(InputType.TYPE_CLASS_NUMBER);
        //binding.tvFactoryArea.setInputType(InputType.TYPE_CLASS_NUMBER);
        viewModel.serviceAreas.observe(this, serviceAreaEntities -> {
            mServiceAreas.clear();
            mServiceAreas.addAll(serviceAreaEntities);
            showCompanyTypeArea();
        });
        viewModel.serviceAreas1.observe(this,serviceAreaEntities -> {
            mServiceAreas1.clear();
            mServiceAreas1.addAll(serviceAreaEntities);
            showCompanyTypeArea1();
        });
        //binding.setBusinessType(mBusinessType);
        //changeViewTip(mBusinessType);
        mPostAreas.clear();
        mProductPostAreas.clear();
        reallyList.clear();
        reallyProductList.clear();
        mAddViewAdapter = new AddViewAdapter(this);
        binding.addView.setAdapter(mAddViewAdapter);
        binding.etProductionRate.setHint("请输入制成率");
        binding.etBusinessVolume.addTextChangedListener(new DecimalInputTextWatcher(binding.etBusinessVolume, 6, 2));
        binding.etWholesalePlaceArea.addTextChangedListener(new DecimalInputTextWatcher(binding.etWholesalePlaceArea, 6, 2));
        binding.etProductionPlaceArea.addTextChangedListener(new DecimalInputTextWatcher(binding.etProductionPlaceArea, 6, 2));
        binding.etTradePlaceArea.addTextChangedListener(new DecimalInputTextWatcher(binding.etTradePlaceArea, 6, 2));
//        binding.comServiceTypeDetail.setEnable(false);
        viewModel.businessType.observe(this, new Observer<List<PickFilterEntity<List<PickFilterEntity>>>>() {
            @Override
            public void onChanged(List<PickFilterEntity<List<PickFilterEntity>>> pickFilterEntities) {
                if (pickFilterEntities != null) {
                    manageTypeList.clear();
                    manageTypeList.addAll(pickFilterEntities);
                    showManageTypePop();
                }
            }
        });
    }

    @Override
    protected void init() {
        //网店编号
        String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
        viewModel.getWebsiteInfo(companyNo, 1);  // 目前固定为企业
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.lin_upload_avatar:
                pictureSelector(true, 500, 1);
                break;
            case R.id.lin_industry:
                viewModel.showIndustryPop();
                break;
            case R.id.lin_company_nature:
                viewModel.getFindEnabledList();
                break;
            case R.id.lin_operating_address:
                Intent intent = new Intent();
                intent.setClass(this, SelectAddressActivity.class);
                intent.putExtra(SelectAddressActivity.TITLE, "经营地址");
                intent.putExtra(SelectAddressActivity.HINT, "请输入地址");
                intent.putExtra(SelectAddressActivity.SAVE_TEXT, "确定");
                if (!TextUtils.isEmpty(viewModel.entity.get().getLatitude())) {
                    intent.putExtra(SelectAddressActivity.LATITUDE, Double.valueOf(Objects.requireNonNull(viewModel.entity.get()).getLatitude()));
                    intent.putExtra(SelectAddressActivity.LONGTITUDE, Double.valueOf(Objects.requireNonNull(viewModel.entity.get()).getLongitude()));
                } else {
                    intent.putExtra(SelectAddressActivity.LATITUDE, 34.20843);
                    intent.putExtra(SelectAddressActivity.LONGTITUDE, 108.91962);
                }
                startActivityForResult(intent, 255);
                break;
            case R.id.lin_company_unit:
                viewModel.getFindUnitList();
                break;
            case R.id.lin_business_type:
                viewModel.getBusinessType();
                break;
            case R.id.tv_add:
                if (!ClickUtils.isDoubleClick()) {
                    isServiceArea = true;
                    if (pickAreas.isEmpty()) {
                        viewModel.getMarketArea();
                    } else {
                        pickTempAreas.clear();
                        pickTempAreas.addAll(pickAreas);
                        showMarketArea(pickTempAreas);
                    }
                }
                break;
            case R.id.tv_add_product:
                if (!ClickUtils.isDoubleClick()) {
                    isServiceArea = false;
                    if (pickAreas.isEmpty()) {
                        viewModel.getMarketArea();
                    } else {
                        pickTempAreas.clear();
                        pickTempAreas.addAll(pickAreas);
                        showMarketArea(pickTempAreas);
                    }
                }
                break;
            case R.id.alltype:
                if (leibusinessType!=-1){
                    viewModel.getBusinessModule(leibusinessType);
                }else {
                    ToastUtil.show(this,"请先选择业务类型");
                }
//                else {
//                    showCompanyTypeArea1();
//                }
                break;
//            case R.id.lin_isProcessing:
//                viewModel.getIsProcessing();
//                break;
//            case R.id.lin_qualityControl:
//                viewModel.getQualityControl();
//                break;
//            case R.id.lin_manage_auth:
//                viewModel.getManageAuthList();
//                break;
//            case R.id.lin_market_area:
//                viewModel.getMarketArea();
//                break;
            case R.id.lin_video_upload:
                viewModel.videoSelector(1, 336);
                break;
//            case R.id.lin_company_mode:
//                viewModel.getBusinessModel();
//                break;
            case R.id.tv_introduction:
                viewModel.getH5Url(getActivity(), viewModel.entity.get().getIntroduction(), "quillEditor", REQUEST_CODE_SELECT, "企业介绍");
                break;
            case R.id.lin_recordUnitName:
                viewModel.getProvinceRecordUnit();
                break;
            case R.id.tv_update:
                if (!ClickUtils.isDoubleClick()) {
                    if (isInputValid()) {
                        if (TextUtils.isEmpty(localVideoUrl)) {
                            viewModel.entity.get().setVideoUrl("");
                            viewModel.entity.get().setVideo("");
                        }
                        uploadAvatar();
                    }
                }
                break;
            case R.id.iv_delete_video:
                localVideoUrl = "";
                binding.linVideoUpload.setVisibility(View.VISIBLE);
                binding.rlVideoView.setVisibility(View.GONE);
                binding.linLabel.setVisibility(View.GONE);
                break;
            case R.id.lin_service_scope:
                if (mServiceAreas.isEmpty()){
                    viewModel.getCompanyServiceScope();
                } else {
                    showCompanyTypeArea();
                }
                break;
            case R.id.manage_type:
                if (!manageTypeList.isEmpty()) {
                    showManageTypePop();
                } else {
                    viewModel.getBusinessType1();
                }
                break;
        }
    }
    private void showManageTypePop() {
        if (manageTypeList.isEmpty()) return;
        if (window == null) {
            window = new OneAndTwoLevelMultipleChoiceWindow(this);
        }
        window.setTitle("经营类型");
        window.setBgView(binding.grayLayout);
        window.setOnResultClick(list1 -> {
            if (list1.size() > 20){
                MToast.showToast(this, "最多选择20个");
                return;
            }
            StringBuilder builderName = new StringBuilder();
            StringBuilder builderCode= new StringBuilder();
            for (PickFilterEntity entity : list1) {
                builderName.append(entity.getName()).append(",");
                builderCode.append(entity.getNo()).append(",");
            }
            comReallyTypes.clear();
            comReallyTypes.addAll(list1);
            binding.manageType.setText(builderName.substring(0, builderName.length() - 1));
            viewModel.entity.get().setServiceTypeName(builderName.substring(0, builderName.length() - 1));
            viewModel.entity.get().setServiceType(builderCode.substring(0, builderCode.length() - 1));
        });
        window.setHistory(manageTypeList, comReallyTypes);
        window.showPopwindow(binding.manageType, Gravity.BOTTOM, 0, 0);
    }
    //经营模式(多选)
    private void showCompanyTypeArea1() {
        if (mServiceAreas1.isEmpty()) return;
        PickFilterEntity mReallyEntity;
        mReallyServiceArea1.clear();
        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
        window.setTitle("经营模式");
        window.setBgView(binding.grayLayout);
        window.setOnResultClick(list1 -> {
            if (list1.size() > 10){
                MToast.showToast(this, "最多选择10个");
                return;
            }
            List<PickFilterEntity> mlist = new ArrayList<>();//临时数据
            mlist.addAll(list1);
            mPostServiceAreas1.clear();
            mHistoryServiceArea1.clear();
            mHistoryServiceArea1.addAll(mlist);
            StringBuilder builderName = new StringBuilder();
            StringBuilder builderid = new StringBuilder();
            if (mlist.size()>0){
                if (TextUtils.isEmpty(mlist.get(0).getNo())){
                    mlist.remove(0);
                }
            }
            for (PickFilterEntity entity : mlist) {
                builderName.append(entity.getName()).append(",");
                builderid.append(entity.getNo()).append(",");
                mPostServiceEntity = new WebsiteInfoEntity.ServiceAreaEntity();
                mPostServiceEntity.id = entity.getNo();
                mPostServiceEntity.name = entity.getName();
                mPostServiceAreas1.add(mPostServiceEntity);
            }
            viewModel.entity.get().getBusinessInfo().setBusinessModelIds(builderid.substring(0, builderid.length() - 1));
            viewModel.entity.get().getBusinessInfo().setBusinessModel(builderName.substring(0, builderName.length() - 1));
            binding.jingyingmode.setText(builderName.substring(0, builderName.length() - 1));

        });
        for (WebsiteInfoEntity.ServiceAreaEntity entity : mServiceAreas1){
            mReallyEntity = new PickFilterEntity();
            mReallyEntity.setName(entity.name);
            mReallyEntity.setNo(entity.id);
            mReallyServiceArea1.add(mReallyEntity);
        }
        window.setSingleData(mReallyServiceArea1, mHistoryServiceArea1);
        window.showPopwindow(binding.jingyingmode, Gravity.BOTTOM, 0, 0);
    }
    //企业服务范围选择器(多选)
    private void showCompanyTypeArea() {
        if (mServiceAreas.isEmpty()) return;
        PickFilterEntity mReallyEntity;
        mReallyServiceArea.clear();
        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
        window.setTitle("服务范围");
        window.setBgView(binding.grayLayout);
        window.setOnResultClick(list1 -> {
            if (list1.size() > 10){
                MToast.showToast(this, "最多选择10个");
                return;
            }
            mPostServiceAreas.clear();
            StringBuilder builderName = new StringBuilder();
            for (PickFilterEntity entity : list1) {
                builderName.append(entity.getName()).append(",");
                mPostServiceEntity = new WebsiteInfoEntity.ServiceAreaEntity();
                mPostServiceEntity.id = entity.getNo();
                mPostServiceEntity.name = entity.getName();
                mPostServiceAreas.add(mPostServiceEntity);
            }
            viewModel.entity.get().setServiceArea(new Gson().toJson(mPostServiceAreas));
            binding.tvServiceScope.setText(builderName.substring(0, builderName.length() - 1));
        });
        for (WebsiteInfoEntity.ServiceAreaEntity entity : mServiceAreas){
            mReallyEntity = new PickFilterEntity();
            mReallyEntity.setName(entity.name);
            mReallyEntity.setNo(entity.id);
            mReallyServiceArea.add(mReallyEntity);
        }
        window.setSingleData(mReallyServiceArea, mHistoryServiceArea);
        window.showPopwindow(binding.tvServiceScope, Gravity.BOTTOM, 0, 0);
    }

    public void showWebsiteInfo(WebsiteInfoEntity entity) {
        binding.setViewModel(entity);
//        if (!TextUtils.isEmpty(entity.getServiceTypeName()) && !TextUtils.isEmpty(entity.getServiceType())){
//            String[] serviceTypeNames = entity.getServiceTypeName().split(",");
//            String[] serviceTypes = entity.getServiceType().split(",");
//            if (serviceTypeNames.length == serviceTypes.length){
//                PickFilterEntity entity1;
//                comReallyTypes.clear();
//                for (int i = 0; i < serviceTypeNames.length; i++) {
//                    entity1 = new PickFilterEntity();
//                    entity1.setName(serviceTypeNames[i]);
//                    entity1.setId(serviceTypes[i]);
//                    comReallyTypes.add(entity1);
//                }
//
//            }
//        }
        viewModel.entity.set(entity);
        setAvatarView(entity.getLogo());
        if (!TextUtils.isEmpty(entity.getIndustryCategoryOneName())) {
            binding.tvIndustryName.setText(entity.getIndustryCategoryOneName() + "/" + entity.getIndustryCategoryTwoName());
        }
        if (!TextUtils.isEmpty(entity.getMainOtherBusiness())){
            binding.huixian.setVisibility(View.VISIBLE);
            binding.huixian.setText(entity.getMainOtherBusiness());
        }
//        if (!TextUtils.isEmpty(entity.getIsProcessing())) {
//            if (TextUtils.equals(entity.getIsProcessing(), "0")) {
//                binding.tvIsProcessing.setText("否");
//            } else {
//                binding.tvIsProcessing.setText("是");
//            }
//        }
//        if (!TextUtils.isEmpty(entity.getQualityControl())) {
//            if (TextUtils.equals(entity.getQualityControl(), "0")) {
//                binding.tvQualityControl.setText("内部");
//            } else {
//                binding.tvQualityControl.setText("第三方");
//            }
//        }
//        if (!TextUtils.isEmpty(entity.getMarketZone())) {
//            List<FilterEntity> filterEntityList = new Gson().fromJson(entity.getMarketZone(), new TypeToken<List<FilterEntity>>() {
//            }.getType());
//            if (filterEntityList.size() > 0) {
//                StringBuilder builder = new StringBuilder();
//                for (FilterEntity areaEntity : filterEntityList) {
//                    builder.append(areaEntity.getName());
//                }
//                binding.tvMarketArea.setText(builder);
//            }
//        }
        binding.tvServiceScope.setText(entity.getServiceAreaNames());//服务范围
        List<WebsiteInfoEntity.ServiceAreaEntity> list = new Gson().fromJson(entity.getServiceArea(), new TypeToken<List<WebsiteInfoEntity.ServiceAreaEntity>>(){}.getType());
        mHistoryServiceArea.clear();
        if (list != null && !list.isEmpty()){
            PickFilterEntity mHistoryEntity;
            for (WebsiteInfoEntity.ServiceAreaEntity serviceAreaEntity : list){
                mHistoryEntity = new PickFilterEntity();
                mHistoryEntity.setName(serviceAreaEntity.name);
                mHistoryEntity.setNo(serviceAreaEntity.id);
                mHistoryServiceArea.add(mHistoryEntity);
            };
        }
        if (!TextUtils.isEmpty(entity.getIntroduction())) {
            String body = ReplaceUtils.INSTANCE.getHtml(entity.getIntroduction());
            binding.tvIntroduction.setText(Html.fromHtml(body, new MImgGetter(getActivity(), binding.tvIntroduction), null));
        }
        if (!TextUtils.isEmpty(entity.getVideoUrl())) {
            localVideoUrl = entity.getVideoUrl();
            binding.linVideoUpload.setVisibility(View.GONE);
            binding.rlVideoView.setVisibility(View.VISIBLE);
            binding.linLabel.setVisibility(View.GONE);
            binding.rlVideoView.setOnClickListener(v -> {
                WebsiteUtils.getInstance().openVideo(WebsiteUpDataQiYeXiXinActivity.this, entity.getVideo(), entity.getVideoUrl(), entity.getCoverUrl());
            });
        }
        if (entity.getBusinessInfo() != null) {
            mHistoryServiceArea1.clear();
            if (!TextUtils.isEmpty(entity.getBusinessInfo().getBusinessModel())&&!TextUtils.isEmpty(entity.getBusinessInfo().getBusinessModelIds())){
                String[] aaa=entity.getBusinessInfo().getBusinessModel().split(",");
                String[] bbb =entity.getBusinessInfo().getBusinessModelIds().split(",");
                binding.jingyingmode.setText(entity.getBusinessInfo().getBusinessModel());
                for (int i=0;i<aaa.length;i++){
                    PickFilterEntity pickFilterEntity =new PickFilterEntity();
                    pickFilterEntity.setName(aaa[i]);
                    pickFilterEntity.setNo(bbb[i]);
                    mHistoryServiceArea1.add(pickFilterEntity);
                }
            }
            leibusinessType =entity.getBusinessInfo().getType();
            changeViewTip(entity.getBusinessInfo().getType());
            binding.setBusinessInfo(entity.getBusinessInfo());
            mBusinessInfoEntity = entity.getBusinessInfo();
            binding.setBusinessType(entity.getBusinessInfo().getType());
            binding.tvBusinessType.setText(entity.getBusinessInfo().typeName);
            mBusinessType = entity.getBusinessInfo().getType();
            mBusinessTypePosition = entity.getBusinessInfo().getType();
            renderTypeView(entity.getBusinessInfo(), entity.getBusinessInfo().getType());
        } else {
            mBusinessInfoEntity = new WebsiteInfoEntity.BusinessInfoEntity();
        }
    }

    private List<PickFilterEntity> areas = new ArrayList<>();
    private void renderTypeView(WebsiteInfoEntity.BusinessInfoEntity entity, int type) {
        String peopleNum = "";
        String annualIncome = "";
        String scope = "";
        String describe = "";
        areas.clear();
        if (type == 0) { //生产型
            peopleNum = TextUtils.isEmpty(entity.staffNumber) ? "" : entity.staffNumber;
            annualIncome = TextUtils.isEmpty(entity.annualIncome) ? "" : entity.annualIncome;
            scope = TextUtils.isEmpty(entity.productionScope) ? "" : entity.productionScope;
            renderFlex(entity.productionArea, false);
            reallyProductList.addAll(entity.productionArea == null ? new ArrayList<>() : entity.productionArea);
            describe = TextUtils.isEmpty(entity.majorBrand) ? "" : entity.majorBrand;
            areas.addAll(entity.mainMarket == null ? new ArrayList<>() : entity.mainMarket);
        } else if (type == 1) {//研发型
            peopleNum = TextUtils.isEmpty(entity.researchNum) ? "" : entity.researchNum;
            annualIncome = TextUtils.isEmpty(entity.annualIncome) ? "" : entity.annualIncome;
            scope = TextUtils.isEmpty(entity.researchRange) ? "" : entity.researchRange;
            describe = TextUtils.isEmpty(entity.researchProduct) ? "" : entity.researchProduct;
            binding.cfkServiceType.setEditContent(TextUtils.isEmpty(entity.customerType) ? "" : entity.customerType);
            areas.addAll(entity.serviceArea == null ? new ArrayList<>() : entity.serviceArea);
        } else if (type == 2) {//贸易型
            peopleNum = TextUtils.isEmpty(entity.staffNumber) ? "" : entity.staffNumber;
            annualIncome = TextUtils.isEmpty(entity.annualIncome) ? "" : entity.annualIncome;
            scope = TextUtils.isEmpty(entity.tradeScope) ? "" : entity.tradeScope;
            describe = TextUtils.isEmpty(entity.tradeBrand) ? "" : entity.tradeBrand;
            areas.addAll(entity.tradeRegion == null ? new ArrayList<>() : entity.tradeRegion);
        } else if (type == 3) {//服务型
            peopleNum = TextUtils.isEmpty(entity.staffNumber) ? "" : entity.staffNumber;
            annualIncome = TextUtils.isEmpty(entity.annualIncome) ? "" : entity.annualIncome;
            scope = TextUtils.isEmpty(entity.serviceScope) ? "" : entity.serviceScope;
            describe = TextUtils.isEmpty(entity.serviceCustomer) ? "" : entity.serviceCustomer;
            binding.cfkServiceType.setEditContent(TextUtils.isEmpty(entity.serviceType) ? "" : entity.serviceType);
            areas.addAll(entity.serviceArea == null ? new ArrayList<>() : entity.serviceArea);
        } else if (type == 4) {
            peopleNum = TextUtils.isEmpty(entity.staffNumber) ? "" : entity.staffNumber;
            annualIncome = TextUtils.isEmpty(entity.annualIncome) ? "" : entity.annualIncome;
            scope = TextUtils.isEmpty(entity.wholesaleScope) ? "" : entity.wholesaleScope;
            describe = TextUtils.isEmpty(entity.majorBrand) ? "" : entity.majorBrand;
            areas.addAll(entity.wholesaleArea == null ? new ArrayList<>() : entity.wholesaleArea);
        } else if (entity.getType() == 5) {
            peopleNum = TextUtils.isEmpty(entity.staffNumber) ? "" : entity.staffNumber;
            annualIncome = TextUtils.isEmpty(entity.annualIncome) ? "" : entity.annualIncome;
            scope = TextUtils.isEmpty(entity.retailScope) ? "" : entity.retailScope;
            describe = TextUtils.isEmpty(entity.retailBrand) ? "" : entity.retailBrand;
            areas.addAll(entity.retailArea == null ? new ArrayList<>() : entity.retailArea);
        }
        binding.etStaffNum.setText(peopleNum);
        binding.etBusinessVolume.setText(annualIncome);
        binding.cfkServiceRange.setEditContent(scope);
        binding.cfkServiceCustomer.setEditContent(describe);
        reallyList.addAll(areas);
        renderFlex(areas, true);
        if (entity.customFields != null) {
            binding.addView.setData(entity.customFields);
        }
    }

    private boolean isInputValid() {
        if (TextUtils.isEmpty(binding.tvIndustryName.getText().toString().trim())) {
            MToast.showToast(this, "请选择行业分类");
            return false;
        }
        if (TextUtils.isEmpty(binding.tvCompanyNature.getText().toString().trim())) {
            MToast.showToast(this, "请选择企业性质");
            return false;
        }
        if (TextUtils.isEmpty(binding.tvConcat.getText().toString().trim())) {
            MToast.showToast(this, "请输入联系人");
            return false;
        }
        if (TextUtils.isEmpty(binding.tvPhone.getText().toString().trim())) {
            MToast.showToast(this, "请输入手机号码");
            return false;
        }
        if (!CheckUtils.isMobile(binding.tvPhone.getText().toString().trim())) {
            MToast.showToast(this, "请输入正确的手机号码");
            return false;
        }
        if (TextUtils.isEmpty(binding.tvOperatingAddress.getText().toString().trim())) {
            MToast.showToast(this, "请选择经营地址");
            return false;
        }
        if (TextUtils.isEmpty(binding.tvServiceScope.getText().toString().trim())) {
            MToast.showToast(this, "请选择服务范围");
            return false;
        }
//        if (TextUtils.isEmpty(binding.cfkMainBusiness.getEditContent())) {
//            MToast.showToast(this, "请输入主营业务");
//            return false;
//        }

        if (!TextUtils.isEmpty(binding.etBusinessVolume.getText())) {
            String businessVolume = binding.etBusinessVolume.getText().toString();
            if (businessVolume.contains(".")){
                mSubEdit = businessVolume.substring(businessVolume.indexOf(".") + 1, businessVolume.length());
                if (mSubEdit.length() > 2) {
                    MToast.showToast(WebsiteUpDataQiYeXiXinActivity.this, "年营业额只能输入到小数点后两位");
                    return false;
                }
            }

        }
        if (!TextUtils.isEmpty(binding.etRetailBusinessVolumeMonth.getText())) {
            String businessVolume = binding.etRetailBusinessVolumeMonth.getText().toString();
            if (businessVolume.contains(".")){
                mSubEdit = businessVolume.substring(businessVolume.indexOf(".") + 1, businessVolume.length());
                if (mSubEdit.length() > 2) {
                    MToast.showToast(WebsiteUpDataQiYeXiXinActivity.this, "月营业额只能输入到小数点后两位");
                    return false;
                }
            }
        }

        if (!TextUtils.isEmpty(binding.etProductionRate.getText().toString())) {
            if (Double.parseDouble(binding.etProductionRate.getText().toString()) > 100.00){
                MToast.showToast(this, "制成率最大为100.00");
                return false;
            }
        }

//        if (!TextUtils.isEmpty(binding.tvMonthProduction.getText().toString().trim())) {
//            if (TextUtils.isEmpty(viewModel.entity.get().getUnitName())) {
//                MToast.showToast(this, "请选择月产量单位");
//                return false;
//            }
//        }
        viewModel.entity.get().setConcat(binding.tvConcat.getText().toString().trim());
        viewModel.entity.get().setPhone(binding.tvPhone.getText().toString().trim());
        viewModel.entity.get().setFixedNumber(binding.tvFixedNumber.getText().toString().trim());
        viewModel.entity.get().setMainBusiness(binding.comServiceTypeDetail.getEditContent());
        viewModel.entity.get().setBusinessIds("");//传空 不然后台报错
//        viewModel.entity.get().setStaffNumber(binding.tvStaffNumber.getText().toString().trim());
//        viewModel.entity.get().setDeveloperNumber(binding.tvDeveloperNumber.getText().toString().trim());
//        viewModel.entity.get().setMonthProduction(binding.tvMonthProduction.getText().toString().trim());
//        viewModel.entity.get().setFactoryArea(binding.tvFactoryArea.getText().toString().trim());
//        viewModel.entity.get().setMainCustomers(binding.cfkMainCustomers.getEditContent());
//        viewModel.entity.get().setMajorBrand(binding.cfkMajorBrand.getEditContent());
        String peopleNum = "";
        String annualIncome = "";
        if (mBusinessType == 3){//服务型
            peopleNum = binding.etStaffNum.getText().toString().trim();
            annualIncome = binding.etBusinessVolume.getText().toString().trim();
            mBusinessInfoEntity.serviceScope = binding.cfkServiceRange.getEditContent().trim();
            mBusinessInfoEntity.serviceCustomer = binding.cfkServiceCustomer.getEditContent().trim();
            mBusinessInfoEntity.serviceType = binding.cfkServiceType.getEditContent().trim();
            mBusinessInfoEntity.serviceArea = mPostAreas;
        } else if (mBusinessType == 4){//批发型
            peopleNum = binding.etStaffNum.getText().toString().trim();
            annualIncome = binding.etBusinessVolume.getText().toString().trim();
            mBusinessInfoEntity.wholesaleScope = binding.cfkServiceRange.getEditContent().trim();
            mBusinessInfoEntity.majorBrand = binding.cfkServiceCustomer.getEditContent().trim();
            mBusinessInfoEntity.wholesaleArea = mPostAreas;
            mBusinessInfoEntity.wholesaleOrder = binding.etWholesaleOrder.getText().toString().trim();
            mBusinessInfoEntity.purchaseOrder = binding.etWholesalePurchaseOrder.getText().toString().trim();
            mBusinessInfoEntity.factoryArea = binding.etWholesalePlaceArea.getText().toString().trim();
        } else if (mBusinessType == 5){//零售型
            peopleNum = binding.etStaffNum.getText().toString().trim();
            annualIncome = binding.etBusinessVolume.getText().toString().trim();
            mBusinessInfoEntity.retailScope = binding.cfkServiceRange.getEditContent().trim();
            mBusinessInfoEntity.retailBrand = binding.cfkServiceCustomer.getEditContent().trim();
            mBusinessInfoEntity.retailArea = mPostAreas;
            mBusinessInfoEntity.retailOrder = binding.etRetailOrder.getText().toString().trim();
            mBusinessInfoEntity.retailStores = binding.etRetailStore.getText().toString().trim();
            mBusinessInfoEntity.monthTurnover = binding.etRetailBusinessVolumeMonth.getText().toString().trim();
        } else if (mBusinessType == 0){//生产型
            peopleNum = binding.etStaffNum.getText().toString().trim();
            annualIncome = binding.etBusinessVolume.getText().toString().trim();
            mBusinessInfoEntity.productionScope = binding.cfkServiceRange.getEditContent().trim();
            mBusinessInfoEntity.majorBrand = binding.cfkServiceCustomer.getEditContent().trim();
            mBusinessInfoEntity.mainMarket = mPostAreas;
            mBusinessInfoEntity.productionArea = mProductPostAreas;
            mBusinessInfoEntity.dayProduction = binding.etDayOutput.getText().toString().trim();
            try {
                mBusinessInfoEntity.productionRate = Double.parseDouble(binding.etProductionRate.getText().toString().trim());
            } catch (Exception e){
                mBusinessInfoEntity.productionRate = 0.00;
            }
            mBusinessInfoEntity.factoryArea = binding.etProductionPlaceArea.getText().toString().trim();
        } else if (mBusinessType == 1){//研发型
            annualIncome = binding.etBusinessVolume.getText().toString().trim();
            mBusinessInfoEntity.researchRange = binding.cfkServiceRange.getEditContent().trim();
            mBusinessInfoEntity.researchProduct = binding.cfkServiceCustomer.getEditContent().trim();
            mBusinessInfoEntity.customerType = binding.cfkServiceType.getEditContent().trim();
            mBusinessInfoEntity.serviceArea = mPostAreas;
            mBusinessInfoEntity.researchNum = binding.etStaffNum.getText().toString().trim();
        } else if (mBusinessType == 2){//贸易型
            peopleNum = binding.etStaffNum.getText().toString().trim();
            annualIncome = binding.etBusinessVolume.getText().toString().trim();
            mBusinessInfoEntity.tradeScope = binding.cfkServiceRange.getEditContent().trim();
            mBusinessInfoEntity.tradeBrand = binding.cfkServiceCustomer.getEditContent().trim();
            mBusinessInfoEntity.tradeRegion = mPostAreas;
            mBusinessInfoEntity.factoryArea = binding.etTradePlaceArea.getText().toString().trim();
            mBusinessInfoEntity.tradeAmount = binding.etTradeVolume.getText().toString().trim();
        }
        if (mBusinessType != 1) {
            mBusinessInfoEntity.staffNumber = peopleNum;
        }
        mBusinessInfoEntity.annualIncome = annualIncome;
        mBusinessInfoEntity.customFields = binding.addView.getDate();
        mBusinessInfoEntity.setType(mBusinessType);
        viewModel.entity.get().setBusinessInfo(mBusinessInfoEntity);
        return true;
    }

    /*
     * 设置企业简介头像信息
     * */
    private void setAvatarView(String url) {
        if (!TextUtils.isEmpty(url)) {
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.image_website_dfg)//图片加载出来前，显示的图片
                    .error(R.mipmap.image_website_dfg)//图片加载失败后，显示的图片
                    .transform(new CircleCrop());
            requestManager.load(url).apply(options).into(binding.ivShopAvatar);
        }
    }

    /*
     * 上传企业简介头像信息
     * */
    private void uploadAvatar() {
        //过滤已上传头像且上传新头像
        if (!TextUtils.isEmpty(avatar)) {
            if (!TextUtils.isEmpty(avatar)) {
                File file = new File(avatar);
                viewModel.uploadAvatarFileModel(file, 1);
            }
        } else {
            viewModel.entity.get().setLogo("");
            viewModel.setWebsiteInfo();
        }
    }

    /*
     * 请求上传简介头像信息的结果回调
     * */
    public void uploadAvatarResult(String toString) {
        avatar = "";
        viewModel.entity.get().setLogo(toString);
        viewModel.setWebsiteInfo();
    }

    /*
     * 选择行业分类后的回调
     * */
    @SuppressLint("SetTextI18n")
    public void selectedIndustry(PickSelectEntity<List<PickSelectEntity>> EntityList, PickSelectEntity entity) {
        viewModel.entity.get().setIndustryCategoryOneName(EntityList.getProjectscale());
        viewModel.entity.get().setIndustryCategoryOneId(EntityList.getNo());
        viewModel.entity.get().setIndustryCategoryTwoName(entity.getProjectscale());
        viewModel.entity.get().setIndustryCategoryTwoId(entity.getNo());
        binding.tvIndustryName.setText(EntityList.getProjectscale() + "/" + entity.getProjectscale());
    }

    /*
     * 请求企业性质数据结果回调
     * */
    public void showCompanyNature(List<PickFilterEntity> list) {
        if (null == picCompanyNature) {
            picCompanyNature = new ArrayList<>();
            picCompanyNature.addAll(list);
        }
        if (picCompanyNature.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                viewModel.entity.get().setCompanyQualityNo(picCompanyNature.get(options1).getNo());
                viewModel.entity.get().setCompanyQualityName(picCompanyNature.get(options1).getName());
                binding.tvCompanyNature.setText(picCompanyNature.get(options1).getName());
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
            projectCategoryOption.setPicker(picCompanyNature);
            projectCategoryOption.setTitleText("企业性质");
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }

    /*
     * 请求地图地址返回的数据
     * */
    private void setAddressText(Intent data) {
        double lat = data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0);
        double lon = data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0);
        String address = data.getStringExtra(SelectAddressActivity.CURRENT_POSITION);
        viewModel.entity.get().setLatitude(lat + "");
        viewModel.entity.get().setLongitude(lon + "");
        binding.tvOperatingAddress.setText(address);
        viewModel.entity.get().setMapAddress(address);
    }

    /*
     * 请求月产量单位返回的数据
     * */
    public void showCompanyUnit(List<PickSelectEntity> list) {
        if (null == picCompanyUnit) {
            picCompanyUnit = new ArrayList<>();
            picCompanyUnit.addAll(list);
        }
        if (picCompanyUnit.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                mBusinessInfoEntity.unit = picCompanyUnit.get(options1).getProjectscale();
                binding.tvCompanyUnit.setText(picCompanyUnit.get(options1).getProjectscale());
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
            projectCategoryOption.setPicker(picCompanyUnit);
            projectCategoryOption.setTitleText("月产量单位");
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }

    /*
     * 请求年营业额返回的数据
     * */
    public void showTurnover(List<PickSelectEntity> list) {
        if (null == picCompanyTurnover) {
            picCompanyTurnover = new ArrayList<>();
            picCompanyTurnover.addAll(list);
        }
        if (picCompanyTurnover.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                viewModel.entity.get().setAnnualIncome(picCompanyTurnover.get(options1).getProjectscale());
                //binding.tvCompanyTurnover.setText(picCompanyTurnover.get(options1).getProjectscale());
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
            projectCategoryOption.setPicker(picCompanyTurnover);
            projectCategoryOption.setTitleText("年营业额");
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }

    /*
     * 请求是否提供加工/定制服务返回的数据
     * */
    public void showIsProcessing(List<PickSelectEntity> list) {
        if (null == picCompanyIsProcessing) {
            picCompanyIsProcessing = new ArrayList<>();
            picCompanyIsProcessing.addAll(list);
        }
        if (picCompanyIsProcessing.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                viewModel.entity.get().setIsProcessing(picCompanyIsProcessing.get(options1).getNo());
                //binding.tvIsProcessing.setText(picCompanyIsProcessing.get(options1).getProjectscale());
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
            projectCategoryOption.setPicker(picCompanyIsProcessing);
            projectCategoryOption.setTitleText("是否提供加工/定制服务");
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }

    /*
     * 请求质量控制返回的数据
     * */
    public void showQualityControl(List<PickSelectEntity> list) {
        if (null == pickQualityControl) {
            pickQualityControl = new ArrayList<>();
            pickQualityControl.addAll(list);
        }
        if (pickQualityControl.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                viewModel.entity.get().setQualityControl(pickQualityControl.get(options1).getNo());
                //binding.tvQualityControl.setText(pickQualityControl.get(options1).getProjectscale());
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
            projectCategoryOption.setPicker(pickQualityControl);
            projectCategoryOption.setTitleText("质量控制");
            projectCategoryOption.setSelectOptions(0);
            projectCategoryOption.show();
        }
    }

    /*
     * 请求业务类型返回的数据
     * */
    public void showBusinessType(List<PickSelectEntity> list) {
        if (null == pickBusinessType) {
            pickBusinessType = new ArrayList<>();
            pickBusinessType.addAll(list);
        }
        if (pickBusinessType.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                //viewModel.entity.get().setQualityControl(pickBusinessType.get(options1).getNo());
                //binding.tvQualityControl.setText(pickBusinessType.get(options1).getProjectscale());
                if (mBusinessType == options1){
                    return;
                }
                mBusinessType = options1;
                mBusinessTypePosition = options1;
                binding.setBusinessType(mBusinessType);
                changeViewTip(mBusinessType);//修改view提示语
                reallyList.clear();

                if (mBusinessType == 0) {
                    reallyProductList.clear();
                }
                //获取经营模式
                leibusinessType =Integer.parseInt(pickBusinessType.get(options1).getNo());
                binding.tvBusinessType.setText(pickBusinessType.get(options1).getProjectscale());
                viewModel.entity.get().getBusinessInfo().setBusinessModelIds("");
                viewModel.entity.get().getBusinessInfo().setBusinessModel("");
                mHistoryServiceArea1.clear();
                binding.jingyingmode.setText("");
            }).setCancelText("取消").setSubCalSize(15)
                    .setCancelColor(getResources().getColor(R.color.color_tab_two))
                    .setSubmitText("确定")
                    .setSubmitColor(getResources().getColor(R.color.color_main)).build();
            projectCategoryOption.setPicker(pickBusinessType);
            projectCategoryOption.setTitleText("业务类型");
            projectCategoryOption.setSelectOptions(mBusinessTypePosition);
            projectCategoryOption.show();
        }
    }

    //根据业务类型动态切换提示
    private void changeViewTip(int mBusinessType) {
        binding.llBusinessArea.setVisibility(View.VISIBLE);
        binding.addView.setData(new ArrayList<>());
        reallyList.clear();
        reallyProductList.clear();
        mPostAreas.clear();
        mProductPostAreas.clear();
        switch (mBusinessType){
            case 3://服务型
                binding.tvStaffNum.setText("员工人数");
                binding.tvServiceRange.setText("服务范围");
                binding.cfkServiceRange.setHint("请输入服务范围");
                binding.tvServiceCustomer.setText("服务客户");
                binding.cfkServiceCustomer.setHint("请输入服务客户");
                binding.llServiceType.setVisibility(View.VISIBLE);
                binding.tvServiceType.setText("服务类型");
                binding.cfkServiceType.setHint("请输入服务类型");
                binding.rlProductArea.setVisibility(View.GONE);
                binding.tvAreaTemp.setText("服务地区");
                binding.etStaffNum.setText("");
                binding.cfkServiceRange.setEditContent("");
                binding.cfkServiceCustomer.setEditContent("");
                binding.cfkServiceType.setEditContent("");
                binding.flexLayout.setVisibility(View.GONE);
                binding.etBusinessVolume.setText("");
            break;
            case 4://批发型
                binding.tvStaffNum.setText("员工人数");
                binding.tvServiceRange.setText("批发范围");
                binding.cfkServiceRange.setHint("请输入批发范围");
                binding.tvServiceCustomer.setText("主营品牌");
                binding.cfkServiceCustomer.setHint("请输入主营品牌");
                binding.llServiceType.setVisibility(View.GONE);
                binding.rlProductArea.setVisibility(View.GONE);
                binding.tvAreaTemp.setText("批发地区");
                binding.etStaffNum.setText("");
                binding.cfkServiceRange.setEditContent("");
                binding.cfkServiceCustomer.setEditContent("");
                binding.cfkServiceType.setEditContent("");
                binding.flexLayout.setVisibility(View.GONE);
                binding.etBusinessVolume.setText("");
                binding.etWholesaleOrder.setText("");
                binding.etWholesalePlaceArea.setText("");
                binding.etWholesalePurchaseOrder.setText("");
                break;
            case 5://零售型
                binding.tvStaffNum.setText("员工人数");
                binding.tvServiceRange.setText("零售范围");
                binding.cfkServiceRange.setHint("请输入零售范围");
                binding.tvServiceCustomer.setText("零售品牌");
                binding.cfkServiceCustomer.setHint("请输入零售品牌");
                binding.llServiceType.setVisibility(View.GONE);
                binding.rlProductArea.setVisibility(View.GONE);
                binding.tvAreaTemp.setText("零售地区");
                binding.etStaffNum.setText("");
                binding.cfkServiceRange.setEditContent("");
                binding.cfkServiceCustomer.setEditContent("");
                binding.cfkServiceType.setEditContent("");
                binding.flexLayout.setVisibility(View.GONE);
                binding.etBusinessVolume.setText("");
                binding.etRetailOrder.setText("");
                binding.etRetailBusinessVolumeMonth.setText("");
                binding.etRetailStore.setText("");
                break;
            case 0://生产型
                binding.tvStaffNum.setText("员工人数");
                binding.tvServiceRange.setText("生产范围");
                binding.cfkServiceRange.setHint("请输入生产范围");
                binding.tvServiceCustomer.setText("主营品牌");
                binding.cfkServiceCustomer.setHint("请输入主营品牌");
                binding.llServiceType.setVisibility(View.GONE);
                binding.rlProductArea.setVisibility(View.VISIBLE);
                binding.tvAreaTemp.setText("主营市场");
                binding.etStaffNum.setText("");
                binding.etBusinessVolume.setText("");
                binding.cfkServiceRange.setEditContent("");
                binding.cfkServiceCustomer.setEditContent("");
                binding.cfkServiceType.setEditContent("");
                binding.flexLayout.setVisibility(View.GONE);
                binding.flexLayoutProduct.setVisibility(View.GONE);
                binding.etProductionPlaceArea.setText("");
                binding.etProductionRate.setText("");
                binding.etDayOutput.setText("");
                break;
            case 1://研发型
                binding.tvStaffNum.setText("研发人数");
                binding.tvServiceRange.setText("研发范围");
                binding.cfkServiceRange.setHint("请输入研发范围");
                binding.tvServiceCustomer.setText("研发产品");
                binding.cfkServiceCustomer.setHint("请输入研发产品");
                binding.llServiceType.setVisibility(View.VISIBLE);
                binding.tvServiceType.setText("客户类型");
                binding.cfkServiceType.setHint("请输入客户类型");
                binding.rlProductArea.setVisibility(View.GONE);
                binding.tvAreaTemp.setText("服务地区");
                binding.etStaffNum.setText("");
                binding.cfkServiceRange.setEditContent("");
                binding.cfkServiceCustomer.setEditContent("");
                binding.cfkServiceType.setEditContent("");
                binding.flexLayout.setVisibility(View.GONE);
                binding.etBusinessVolume.setText("");
                break;
            case 2://贸易型
                binding.tvStaffNum.setText("员工人数");
                binding.tvServiceRange.setText("贸易范围");
                binding.cfkServiceRange.setHint("请输入贸易范围");
                binding.tvServiceCustomer.setText("贸易品牌");
                binding.cfkServiceCustomer.setHint("请输入贸易品牌");
                binding.llServiceType.setVisibility(View.GONE);
                binding.rlProductArea.setVisibility(View.GONE);
                binding.tvAreaTemp.setText("主营市场");
                binding.etStaffNum.setText("");
                binding.cfkServiceRange.setEditContent("");
                binding.cfkServiceCustomer.setEditContent("");
                binding.cfkServiceType.setEditContent("");
                binding.flexLayout.setVisibility(View.GONE);
                binding.etTradePlaceArea.setText("");
                binding.etTradeVolume.setText("");
                binding.etBusinessVolume.setText("");
                break;
        }

    }


    /*
     * 请求管理体系认证返回的数据
     * */
    public void showCompanyAuth(List<PickFilterEntity> list) {
        if (null == pickManageAuth) {
            pickManageAuth = new ArrayList<>();
            pickManageAuth.addAll(list);
        }
        if (pickManageAuth.size() > 0) {
            TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
            window.setTitle("管理体系认证");
            window.setBgView(binding.grayLayout);
            window.setOnResultClick(list1 -> {
                StringBuilder builder = new StringBuilder();
                for (PickFilterEntity entity : list1) {
                    builder.append(entity.getName()).append(",");
                }
                viewModel.entity.get().setManageAuth(builder.substring(0, builder.length() - 1));
                //binding.tvManageAuth.setText(builder.substring(0, builder.length() - 1));
            });
            window.setSingleData(pickManageAuth);
            //window.showPopwindow(binding.linMarketArea, Gravity.BOTTOM, 0, 0);
        }
    }

    /*
     * 请求备案单位返回的数据
     * */
//    public void showRecordUnit(List<PickFilterEntity<List<PickFilterEntity>>> list) {
//        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
//        window.setTitle("备案单位");
//        window.setBgView(binding.grayLayout);
//        window.setOnResultClick(list1 -> {
//            StringBuilder builder = new StringBuilder();
//            StringBuilder builder1 = new StringBuilder();
//            for (PickFilterEntity entity : list1) {
//                builder.append(entity.getName()).append(",");
//                builder1.append(entity.getNo()).append(",");
//            }
//            viewModel.entity.get().setRecordUnitName(builder.substring(0, builder.length() - 1));
//            viewModel.entity.get().setRecordUnit(builder1.substring(0, builder1.length() - 1));
//            binding.tvRecordUnitName.setText(builder.substring(0, builder.length() - 1));
//        });
//        window.setData(list);
//        window.showPopwindow(binding.linRecordUnitName, Gravity.BOTTOM, 0, 0);
//    }

    public void showRecordUnit(List<PickFilterEntity<List<PickFilterEntity>>> list) {
        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
        window.setTitle("备案单位");
        window.setBgView(binding.grayLayout);
        window.setOnResultClick(list1 -> {
            StringBuilder builder = new StringBuilder();
            StringBuilder builder1 = new StringBuilder();
            for (PickFilterEntity entity : list1) {
                builder.append(entity.getName()).append(",");
                builder1.append(entity.getNo()).append(",");
            }
            viewModel.entity.get().setRecordUnitName(builder.substring(0, builder.length() - 1));
            viewModel.entity.get().setRecordUnit(builder1.substring(0, builder1.length() - 1));
            binding.tvRecordUnitName.setText(builder.substring(0, builder.length() - 1));
            historyList.clear();
            historyList.addAll(list1);
        });
        window.setData(list, historyList);
        window.showPopwindow(binding.linRecordUnitName, Gravity.BOTTOM, 0, 0);
    }

    /*
     * 请求市场区域返回的数据
     * */
    public void showMarketArea(List<PickFilterEntity<List<PickFilterEntity>>> list) {
        pickAreas.clear();
        pickAreas.addAll(list);
        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
        window.setTitle(isServiceArea ? binding.tvAreaTemp.getText().toString() : binding.tvProductTemp.getText().toString());
        window.setBgView(binding.grayLayout);
        window.setOnResultClick(list1 -> {
            if (isServiceArea) {
                if (reallyList.size() + list1.size() > 20) {
                    MToast.showToast(this, "最多20条");
                    return;
                }
                for (PickFilterEntity entity : list1){
                    if (!reallyList.contains(entity)){
                        reallyList.add(entity);
                    }
                }
                renderFlex(reallyList, isServiceArea);
            } else {
                if (reallyProductList.size() + list1.size() > 20) {
                    MToast.showToast(this, "最多20条");
                    return;
                }
                 for (PickFilterEntity entity : list1){
                    if (!reallyProductList.contains(entity)){
                        reallyProductList.add(entity);
                    }
                }
                renderFlex(reallyProductList, isServiceArea);
            }
            //List<AddEntity> addEntities = new ArrayList<>();
            //StringBuilder builder = new StringBuilder();
//            for (PickFilterEntity entity : list1) {
//                builder.append(entity.getName()).append(",");
//                AddEntity filterEntity = new AddEntity();
//                filterEntity.setName(entity.getName());
//                filterEntity.setNo(entity.getNo());
//                addEntities.add(filterEntity);
//            }
            //viewModel.entity.get().setMarketZone(new Gson().toJson(addEntities).toString());
            //binding.tvMarketArea.setText(builder.substring(0, builder.length() - 1));
        });
        window.setData(list);
        window.setSecondMost(20);
        window.showPopwindow(isServiceArea ? binding.tvAdd : binding.tvAddProduct, Gravity.BOTTOM, 0, 0);
    }

    PickFilterEntity filterEntity;
    private void renderFlex(List<PickFilterEntity> list, boolean isServiceArea) {
        if (isServiceArea) {
            mPostAreas.clear();
        } else {
            mProductPostAreas.clear();
        }
        if (list.isEmpty())return;
        if (isServiceArea){
            binding.flexLayout.removeAllViews();
            binding.flexLayout.setVisibility(View.VISIBLE);
        } else {
            binding.flexLayoutProduct.removeAllViews();
            binding.flexLayoutProduct.setVisibility(View.VISIBLE);
        }
        for (PickFilterEntity entity : list){
            View view = LayoutInflater.from(this).inflate(R.layout.item_area_bg, isServiceArea ? binding.flexLayout : binding.flexLayoutProduct, false);
            TextView tvName = view.findViewById(R.id.tvName);
            tvName.setText(entity.getName());
            tvName.setOnClickListener(v -> {
                if (isServiceArea){
                    mPostAreas.remove(entity);
                    binding.flexLayout.removeView(view);
                } else {
                    mProductPostAreas.remove(entity);
                    binding.flexLayoutProduct.removeView(view);
                }
            });
            filterEntity = new  PickFilterEntity(entity.getNo(), entity.getName());
            if (isServiceArea) {
                if (!mPostAreas.contains(filterEntity)) {
                    mPostAreas.add(filterEntity);
                    binding.flexLayout.addView(view);
                }

            } else {
                if (!mProductPostAreas.contains(filterEntity)) {
                    mProductPostAreas.add(filterEntity);
                    binding.flexLayoutProduct.addView(view);
                }
            }
        }
    }

    /*
     * 请求经营模式返回的数据
     * */
    public void showBusinessMode(List<PickFilterEntity> list) {
        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
        window.setTitle("经营模式");
        window.setBgView(binding.grayLayout);
        window.setOnResultClick(list1 -> {
            StringBuilder builder = new StringBuilder();
            for (PickFilterEntity entity : list1) {
                builder.append(entity.getName()).append(",");
            }
            viewModel.entity.get().setBusinessModel(builder.substring(0, builder.length() - 1));
            //binding.tvCompanyMode.setText(builder.substring(0, builder.length() - 1));
        });
        window.setSingleData(list);
        //window.showPopwindow(binding.linMarketArea, Gravity.BOTTOM, 0, 0);
    }

    /*
     * 请求上传视频返回的数据
     * */
    public void uploadVideoResult(String videoId, UploadFileInfo info) {
        viewModel.entity.get().setVideo(videoId);
        runOnUiThread(() -> {
            DialogHelper.dismissProgressDialog();
            if (!TextUtils.isEmpty(localVideoUrl)) {
                viewModel.entity.get().setVideoUrl(localVideoUrl);
                binding.linVideoUpload.setVisibility(View.GONE);
                binding.rlVideoView.setVisibility(View.VISIBLE);
                binding.linLabel.setVisibility(View.GONE);
                binding.rlVideoView.setOnClickListener(v -> {
                    List<VideoBean> videoBeanList = new ArrayList<>();
                    VideoBean videoBean = new VideoBean();
                    videoBean.setVideoId(videoId);
                    videoBean.setCoverURL(localVideoUrl);
                    videoBean.setCover("");
                    videoBeanList.add(videoBean);
                    Intent intent = new Intent(getActivity(), PlayListActivity.class);
                    intent.putExtra(PlayListActivity.VIDEOLISTBEAN, (Serializable) videoBeanList);
                    intent.putExtra(PlayListActivity.PSO, 0);
                    intent.putExtra(PlayListActivity.IS_ShOW_USER, false);
                    intent.putExtra(PlayListActivity.VIDEOTYPE, "website_video");
                    getActivity().startActivity(intent);
                });
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_SELECT && resultCode == RESULT_CODE_SELECT) { //企业简介返回
            if (data != null) {
                String body = data.getStringExtra("body").trim();
                viewModel.entity.get().setIntroduction(body);
                body = ReplaceUtils.INSTANCE.getHtml(body);
                binding.tvIntroduction.setText(Html.fromHtml(body, new MImgGetter(getActivity(), binding.tvIntroduction), null));
            }
        }
        if (resultCode != RESULT_OK)
            return;
        switch (requestCode) {
            case 255://地图地址选择回调
                if (data == null)
                    return;
                setAddressText(data);
                break;
            case 336:
                List<LocalMedia> selectList1 = PictureSelector.obtainMultipleResult(data);
                localVideoUrl = selectList1.get(0).getRealPath();
                Glide.with(this)
                        .asBitmap()
                        .load(localVideoUrl)
                        .apply(new RequestOptions().placeholder(R.drawable.null_img_list))
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                                binding.ivVideoCoverUrl.setImageBitmap(resource);
                            }
                        });
                viewModel.getVideoParamsSTS(localVideoUrl);
                break;
        }
    }

    @Override
    protected void onPictureSelectorResult(List<LocalMedia> selectList) {
        //LogUtil.i("api", "====================" + selectList.get(0).getRealPath());
        setAvatarView(selectList.get(0).getRealPath());
        avatar = selectList.get(0).getRealPath();
    }

    /*
     * 编辑网站信息成功后的回调
     * */
    public void editWebsiteInfo() {
        finish();
    }

}
